<template>
  <div class="innerPage" v-if="falg">
    <div class="inner-img">
      <div class="img-bg" v-if="VideoIndexOf(Contentlist.files ? Contentlist.files : Contentlist.cover)"
        :style="'background-image:url(' + Contentlist.cover + ') '">
      </div>
      <div class="videoContainer" v-else>
        <!-- <video class="fullscreenVideo" id="bgVid" playsinline="" autoplay="" muted="" loop="">
          <source :src="Contentlist.collection.cover" type="video/mp4">
        </video> -->
        <vdeo :collection="Contentlist.files" />
      </div>
    </div>
    <div class="bottom-bg"></div>
    <van-row justify="center">
      <van-col span="24" class="inner-title">
        <h1>{{ Contentlist.name }}</h1>
      </van-col>
      <van-col span="24" class="inner-title">
        <p>{{ Contentlist.userCode }}</p>
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon" style="margin-top:30px">
      <van-col span="24">购买时间：{{ Contentlist.payTime }}</van-col>
    </van-row>
    <div class="collect-info">
      {{ Contentlist.propType == 3 ? "盲盒信息" : "藏品信息" }}
    </div>
    <van-row justify="end" class="colletion-authon">
      <van-col span="12">创作者</van-col>
      <van-col span="12" class="right"><span>{{ Contentlist.serviceProvider }}</span></van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="12">发行方</van-col>
      <van-col span="12" class="right"><span>{{ Contentlist.mechanism }}</span>
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="6">合约地址</van-col>
      <van-col span="18" class="right">
        <p>{{ Contentlist.assetId }}</p>
        <img src="../../assets/image/icon/copids.png" alt="" @click="copy">
      </van-col>
    </van-row>
    <div class="collect-info">
      藏品详情
    </div>
    <div class="story">
      <img :src="Contentlist.certificatePictureUrl" alt="" @click="openImg(Contentlist.certificatePictureUrl)">
      <!-- <div class="certificate">
        <img src="../../assets/image/certificate-header.png" alt="" class="certificate-img">
        <h1>数字藏品鉴定证书</h1>
        <div class="certificate-time">
          <p>区块链网络全球通用协调时间</p>
          <p>Wed Jan 16 08:50:20 UTC 2019</p>
        </div>
        <div class="certificate-code">
          <img src="../../assets/image/tabbg.png" alt="">
          <p>扫码查看作品存证详情</p>
        </div>
        <div class="certificate-content">
          <img src="../../assets/image/border.png" alt="" class="borders">
          <div>
            <p>藏品鉴定ID：</p>
            <p>A4564S</p>
          </div>
          <div>
            <p>数字藏品名称：</p>
            <p>后台配置的藏品名称</p>
          </div>
          <div>
            <p>鉴定人姓名：</p>
            <p>后台配置的鉴定人姓名</p>
          </div>
          <div>
            <p>鉴定人职业：</p>
            <p>后台配置的鉴定人职业</p>
          </div>
          <div>
            <p>存证时间：</p>
            <p>2022年12月01日 15:59:59</p>
          </div>
          <div>
            <p>存证平台：</p>
            <p>区块链存证网站链接</p>
          </div>
          <img src="../../assets/image/border.png" alt="" class="borders">
        </div>
        <p class="statement">区块链电子存证</p>
      </div> -->
      <div v-html="Contentlist.story">
      </div>
    </div>
    <van-row justify="space-between" class="footer" v-if="Contentlist.whereabouts == 1">
      <van-col span="24" class="button" v-if="Contentlist.whereabouts == 1 && Contentlist.isOpenBox != 2">
        <van-button type="primary" @click="cancel" block>
          <span>取消出售</span>
        </van-button>
      </van-col>
    </van-row>
    <van-row justify="space-between" class="footer" v-if="!Contentlist.whereabouts">
      <van-col span="7">
        <van-button type="primary" @click="toGive">
          <span>转赠</span>
        </van-button>
      </van-col>
      <van-col span="7">
        <van-button type="primary" @click="goSel(2)">
          <span>竞拍</span>
        </van-button>
      </van-col>
      <van-col class="right" span="7">
        <van-button type="primary" @click="goSel(0)">
          <span>出售</span>
        </van-button>
      </van-col>
    </van-row>
    <van-popup v-model:show="popupshow">
      <div class="gift-warp">
        <van-icon name="cross" @click="popupshow = false" />
        <img src="@/assets/image/gift.png" alt="">
        <h1>实付：￥{{ Contentlist.price }}</h1>
        <van-button round type="primary" class="box-btn" @click="openBox">拆盲盒</van-button>
      </div>
    </van-popup>
  </div>
</template>
<script>
import { defineComponent, ref, reactive, toRefs, onMounted } from 'vue'
import Clipboard from 'clipboard';
import useClipboard from 'vue-clipboard3'
import { useRouter } from "vue-router"
import { getCollectionInf, openBlindBox, collectionInfo, cancelSell } from "@/api/public";
import { Toast, ImagePreview } from "vant";
import { VideoIndexOf } from "@/utils/phone";
import vdeo from "@/components/video.vue";
export default {
  components: { vdeo },
  setup(props) {
    const { toClipboard } = useClipboard()
    const router = useRouter()
    const formData = reactive({
      isOpenBox: router.currentRoute.value.query.type
    })
    const falg = ref(false)
    const popupshow = ref(false)
    const Contentlist = ref({})
    const Available = reactive([
      {
        image: require('@/assets/image/product.png'),
        name: "臧品系列名"
      },
      {
        image: require('@/assets/image/product.png'),
        name: "臧品系列名"
      }, {
        image: require('@/assets/image/product.png'),
        name: "臧品系列名"
      }
    ])
    const cancel = async () => {
      const data = {
        userCollectionId: router.currentRoute.value.query.userCollectionId
      }
      const res = await cancelSell(data)
      if (res.data.success) {
        Toast("操作成功")
        onload()
      }
    }
    const openImg = (url) => {
      ImagePreview([url]);
    }
    const toGive = () => {
      router.push({
        path: "/Givefriends",
        query: {
          id: router.currentRoute.value.query.userCollectionId,
          img: Contentlist.value.cover,
          name: Contentlist.value.collectionName,
          code: Contentlist.value.code
        }
      })
    }
    const copy = async () => {
      try {
        await toClipboard(Contentlist.value.assetId)
        Toast("复制成功")
      } catch (e) {
        console.error(e)
      }
    }
    const goSel = (type) => {
      // return Toast("还在开发中")
      router.push({
        path: '/sellPage',
        query: {
          id: router.currentRoute.value.query.userCollectionId,
          type: type
        }
      })
    }
    const pop = () => {
      popupshow.value = true
    }
    const openBox = async () => {
      let id = router.currentRoute.value.query.id
      const res = await openBlindBox(id)
      console.log(res)
      if (res.data.success) {
        onload()
        Toast(res.data.message)

      }
      popupshow.value = false
    }
    const onload = () => {
      const data = { collectionId: router.currentRoute.value.query.id, userCollectionId: router.currentRoute.value.query.userCollectionId, }
      collectionInfo(data).then(res => {
        console.log(res.data.data)
        if (res.data.success) {
          falg.value = true
          Contentlist.value = res.data.data
        }

      })
    }
    onMounted(() => {
      console.log(router.currentRoute.value.query.type)
      onload()

    })

    return {
      Contentlist, Available, copy, openBox, formData, goSel, toGive, popupshow, pop, falg
      , VideoIndexOf, cancel, openImg
    }
  }
}
</script>
<style lang="less" scoped>
&:deep(.van-popup) {
  background: #000 !important;
}

.gift-warp {
  padding-top: 50px;

  i {
    top: 20px;
    right: 20px;
    position: absolute;
    color: #fefefe;
    font-size: 60px;
  }

  img {
    display: block;
    width: 625px;
    height: 415px;
    margin: 50px auto 0px;
  }

  .box-btn {
    font-size: 32px;
    display: block;
    border: none;
    width: 448px;
    height: 80px;
    background: linear-gradient(-90deg, #37dc6d, #34d1f9);
    margin: 20px auto;
  }

  h1 {
    text-align: center;
    font-size: 48px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #f3e3bb;
    line-height: 42px;
    margin: 40px 0px;
  }

  width: 688px;
  height: 777px;
  background-image: url('../../assets/image/giftbg.png');
  background-size: 100% 100%;
}

.videoContainer {
  overflow: hidden;
  border-radius: 80px;
  border: 1px solid #999;

  .fullscreenVideo {
    width: 648px;
    height: 648px;
  }
}

.innerPage {
  padding-bottom: 148px;

  .inner-img {
    overflow: hidden;
    width: 648px;
    height: 648px;
    background: linear-gradient(0deg, #161718, #4b4c4d);
    border: 2px solid #ffffff;
    border-radius: 80px;
    margin: 80px auto 20px;

    .img-bg {
      width: 648px;
      height: 648px;
      background-size: cover;
      // margin: 100px auto;
      position: relative;
      background-position: center center;
      background-repeat: no-repeat;
    }
  }

  .bottom-bg {
    background: url('../../assets/image/bottom.png');
    width: 660px;
    height: 220px;
    background-size: cover;
    margin: 0px auto;
  }

  .inner-title {
    text-align: center;

    h1 {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f8f8f8;
      line-height: 103px;
      margin: 0px;
    }

    p {
      font-size: 36px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f8f8f8;
      background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  .Limit-warp {
    span {
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      line-height: 48px;
    }

    span:nth-child(1) {
      color: #444442;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      background: #f3e3bb;
      border-radius: 4px 0px 0px 4px;
      padding: 3px 12px;
    }

    span:nth-child(2) {
      padding: 3px 12px;
      background: #444442;
      border-radius: 4px;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f3e3bb;
      line-height: 48px;
    }
  }

  .colletion-authon {
    padding: 0px 18px;
    font-size: 34px;

    color: #ffffff;
    line-height: 140px;
    margin: 30px 20px 0px;
    background: #282a2c;
    border: 1px solid #ffffff;
    border-bottom-color: #999;
    box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;

    p {
      font-size: 30px;
      color: #b9c4c7;
      line-height: 140px;
    }

    .right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      text-align: right;

      p {
        width: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      img {
        width: 40px;
        margin-left: 20px;
      }

      span {
        text-align: center;
        font-size: 30px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #fefefe;
        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
  }

  .collect-info {
    z-index: 1;
    margin-top: 50px;
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #f8f8f8;
    margin-left: 20px;
    padding-left: 40px;
    position: relative;
  }

  .collect-info::after {
    opacity: 0.8;
    z-index: -1;
    background-size: 100% 100%;
    width: 70px;
    height: 60px;
    top: -10px;
    left: 0;
    position: absolute;
    content: '';
    background-image: url('../../assets/image/point.png');
  }

  .Available {
    background: #282a2c;
    border-radius: 20px;
    margin: 30px 20px;
    padding: 20px 10px;

    .between-warp {
      position: relative;

      img {
        width: 180px;
        height: 141px;
      }
    }

    .img-warp {
      padding: 30px 10px;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
    }
  }

  .story {
    background: #282a2c;
    border: 1px solid #ffffff;
    box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;
    margin: 30px 30px;
    padding: 60px 30px;
    font-size: 28px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 48px;

    ::v-deep img {
      width: 100%;
    }

    img {
      width: 100% !important;
    }

    /deep/ img {
      width: 100% !important;
    }
  }

  .footer {
    .button {
      button {
        width: 100%;
      }
    }

    width: 710px;
    padding: 30px 20px;
    background: #333;
    position: fixed;
    bottom: 0px;
    z-index: 999;
    display: flex;
    align-items: center;

    .price {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #f8f8f8;
    }

    .right {
      text-align: right;
      display: flex;
      justify-content: flex-end;
    }

    .block {
      &:deep(.van-button) {
        border: none;
        width: 100%;
        height: 88px;
        background: linear-gradient(-90deg, #37dc6d, #34d1f9);
        border-radius: 44px;

        span {
          display: block;
        }
      }
    }

    &:deep(.van-button) {
      border: none;
      width: 100%;
      height: 88px;
      background: linear-gradient(-90deg, #37dc6d, #34d1f9);
      border-radius: 44px;

      span {
        display: block;
      }
    }
  }
}

.certificate {
  width: 100%;
  background: url(../../assets/image/certificate.png) no-repeat;
  background-size: 100% 100%;
  padding: 20px 0;
  margin-bottom: 20px;

  .certificate-img {
    width: 373px;
    height: 94px;
    display: block;
    margin: 30px auto;
  }

  h1 {
    width: 100%;
    text-align: center;
    padding: 20px 0;
    font-size: 61px;
    font-family: Source Han Serif SC;
    font-weight: bold;
    color: #FFCC90;
  }

  .certificate-time {
    p {
      width: 100%;
      text-align: center;
      display: block;
      font-weight: 400;
      font-size: 23px;
      font-family: Adobe Heiti Std;
      font-weight: normal;
      color: #FFCC90;
      line-height: 38px;
    }
  }

  .certificate-content {
    width: 100%;
    padding: 30px 0;
    display: flex;
    flex-flow: wrap;
    align-items: center;
    justify-content: center;

    div {
      width: 100%;
      display: flex;
      flex-flow: nowrap;
      justify-content: center;
      align-items: center;

      p:first-child {
        width: 40%;
        text-align: right;
        font-size: 28px;
        font-family: Source Han Serif SC;
        font-weight: bold;
        color: #FFFFFF;
        line-height: 63px;
      }

      p:last-child {
        width: 60%;
        text-align: left;
        font-size: 28px;
        font-family: Source Han Serif SC;
        font-weight: bold;
        color: #FFE2BF;
        line-height: 63px;
      }
    }
  }

  .certificate-code {
    width: 100%;
    text-align: center;

    img {
      margin: 20px auto;
      width: 272px !important;
      height: 272px !important;
      border: 4px solid #FFCC90;
      border-radius: 10px;
      padding: 15px;
    }

    p {
      font-size: 27px;
      font-family: Source Han Serif SC;
      font-weight: 600;
      color: #FFCC90;
      line-height: 28px;
    }
  }

  .borders {
    width: 555px;
    height: 29px;
    display: block;
  }

  .statement {
    font-size: 38px;
    font-family: Source Han Serif SC;
    font-weight: bold;
    color: #FFCC90;
    line-height: 79px;
    margin: 26px auto;
    text-align: center;
  }
}

.wp30 {
  width: 30%;
}
</style>